# -*- coding:UTF-8 -*-
'''
开发环境：PyCharm
创建日期：2025/8/20 10:45
作   者：新启典学苑-樱桃
描   述：pip install requests

    发送get请求
       1. 参数拼接在URL后面
       2. 参数构造成字典，使用params传参
'''
import requests
base_url = "http://192.168.1.29:8088"
def test_recharge1():
    print("测试充值功能，充值金额为1000，充值成功")
    url = base_url + "/futureloan/mvc/api/member/recharge?mobilephone=18012345678&amount=1000"
    r = requests.get(url)  # 发送get请求，接收响应
    print(r.text)  # 打印文本格式的响应体（字符串）
    print(r.json()) # json格式的响应体（字典）
    a = r.json()
    # a 实际结果， == 后面是预期结果
    assert a['code'] == "10001"
    assert a['msg'] == "充值成功"
    assert a['status'] == 1

def test_recharge2():
    print("测试充值功能，充值金额为500000，充值成功")
    url = base_url + "/futureloan/mvc/api/member/recharge"
    cs = {
        "mobilephone": "18012345678",
        "amount": 500000
    }
    r = requests.get(url, params=cs)  # 发送get请求，接收响应
    print(r.text)  # 打印文本格式的响应体（字符串）
    print(r.json()) # json格式的响应体（字典）
    a = r.json()
    # a 实际结果， == 后面是预期结果
    assert a['code'] == "10001"
    assert a['msg'] == "充值成功"
    assert a['status'] == 1

def test_recharge3():
    print("测试充值功能，充值金额为0，充值失败")
    url = base_url + "/futureloan/mvc/api/member/recharge"
    hds = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"}
    cs = {"mobilephone": "18012345678","amount": 0}
    r = requests.get(url, params=cs, headers=hds) # 伪装成浏览器发送的请求。
    print("状态码：", r.status_code)  # 200
    print("响应头：", r.headers)
    print("请求头：", r.request.headers)  # User-Agent
    print("Cookie：", r.cookies)
    print("文本格式的响应体：", r.text)
    print("响应体：", r.content)  # byte 字节码














